﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.DALFactory;
using ECCIT;
using System.Linq;
using OgilvyOne.UKNow.IDAL;
using OgilvyOne.UKNow.DAL;
using OgilvyOne.UKNow.ServiceReference;
using OgilvyOne.Model;
using OgilvyOne.Utility;
using OgilvyOne.BLL;

namespace OgilvyOne.UKNow.BLL
{
    public class VotesKeyWordsBLL
    {
        public int LanguageID { get; set; }
        public VotesKeyWordsBLL(int langID)
        {
            this.LanguageID = langID;
        }
        //获取所有关键字
        public IList<VotesKeyWordsModel> selectKeyWords()
        {
            VotesKeyWordsIDAL use = VotesKeyWordsDALFactory.Create(LanguageID);
            return use.GetAllVotesKeyWordsModels();
            
        }
        //获取所有系统的并可发布的关键字
        public IList<VotesKeyWordsModel> selectKeyWordsNrelsy()
        {
            VotesKeyWordsIDAL use = VotesKeyWordsDALFactory.Create(LanguageID);
            return use.GetAllVotesKeyWordsModelsReleaseNsy();

        }
        //根据名称获取改关键字信息
        public IList<VotesKeyWordsModel> selectKeyWords(string kname)
        {
            VotesKeyWordsIDAL use = VotesKeyWordsDALFactory.Create(LanguageID);
            return use.GetAllVotesKeyWordsModelsByName(kname);

        }
        //根据关键字Kid 获取该关键字信息
        public VotesKeyWordsModel selKeyWords(int Kid)
        {
            VotesKeyWordsIDAL use = VotesKeyWordsDALFactory.Create(LanguageID);
            return use.GetVotesKeyWordsModelByID(Kid);
        }
        //新增关键字
        public ResultInfo Save(VotesKeyWordsModel info)
        {
            VotesKeyWordsIDAL use = VotesKeyWordsDALFactory.Create(LanguageID);
            return use.Save(info);
        }
        //删除关键字的数据
        public ResultInfo delKeyWords(int eid)
        {
            IList<int?> list = new List<int?>();
            list.Add(eid);
            VotesKeyWordsIDAL use = VotesKeyWordsDALFactory.Create(LanguageID);
            return use.Delete(list);
        }
        //修个单个关键字的发布状态
        public void modPubOne(int eid)
        {
            List<int?> list = new List<int?>();
            list.Add(eid);

            VotesKeyWordsIDAL use = VotesKeyWordsDALFactory.Create(LanguageID);

            VotesKeyWordsModel model = use.GetVotesKeyWordsModelByID(eid); //查看该关键字的当前发布状态
            if (model.State > 0) //该关键字的当前为发布状态
            {
                use.UnPublish(list);
                //设置为该关键字的state为0 不发布 (传递参数 eid 和 int=0)
            }
            else
            {
                use.Publish(list);
                //设置该关键字的state为1 发布     (传递参数 eid 和 int=1)
            }
        }
       
    }
}
